package com.ibeetl.admin.api.web;

import com.ibeetl.admin.api.entity.Travel_attractions_line;
import com.ibeetl.admin.api.entity.Travel_attractions_line_info;
import com.ibeetl.admin.api.entity.Travel_attractions_line_vo;
import com.ibeetl.admin.api.service.TravelAttractionsLineService;
import com.ibeetl.admin.console.web.query.AuditQuery;
import com.ibeetl.admin.core.annotation.Function;
import com.ibeetl.admin.core.web.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

@RestController
@Tag(
        name = "TravelAttractionsLineController")
public class TravelAttractionsLineController {

    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/api/travel_attractions_line";
    private static final String MODEL_WEB = "/web/travel_attractions_line";
    @Resource
    private TravelAttractionsLineService travelAttractionsLineService;



    /*页面*/
    @GetMapping(MODEL_WEB + "/index.do")
    @Function("trace")
    public ModelAndView index() {
        ModelAndView view = new ModelAndView("/admin/attractionsLine/index.html");
        view.addObject("search", AuditQuery.class.getName());
        return view;
    }


    @Operation(
            summary = "新增景点路线"
    )
    @PostMapping(MODEL + "/add.json")
    @CrossOrigin
    public JsonResult<Travel_attractions_line> add(Travel_attractions_line travel_attractions_line) throws InvocationTargetException, IllegalAccessException {
        if(travel_attractions_line.getUserId() == null){
            return JsonResult.failMessage("导游ID不可为空");
        }
        if(travelAttractionsLineService.saveData(travel_attractions_line)){
            Long attraction_id = travelAttractionsLineService.queryNewIdByUserId(travel_attractions_line.getUserId());
            travel_attractions_line.setAttractionId(attraction_id);
            return JsonResult.success(travel_attractions_line);
        }else{
            return JsonResult.failMessage("新增失败！");
        }

    }
    @Operation(
            summary = "更新景点路线"
    )
    @PostMapping(MODEL + "/update.json")
    @CrossOrigin
    public JsonResult<Travel_attractions_line> update(Travel_attractions_line travel_attractions_line) throws InvocationTargetException, IllegalAccessException {

        travelAttractionsLineService.updateData(travel_attractions_line);
        return JsonResult.success(travel_attractions_line);
    }


    @Operation(
            summary = "更新景点路线浏览次数"
    )
    @PostMapping(MODEL + "/addViewsNum.json")
    @CrossOrigin
    public JsonResult addViewsNum(Long attractionId) {

        travelAttractionsLineService.addViewsNum(attractionId);
        return JsonResult.success();
    }



    @Operation(
            summary = "更新景点路线点赞次数"
    )
    @PostMapping(MODEL + "/addLikeNum.json")
    @CrossOrigin
    public JsonResult addLikeNum(Long attractionId){
        travelAttractionsLineService.addLikeNum(attractionId);
        return JsonResult.success();
    }



    @PostMapping(MODEL_WEB + "/audit.json")
    @CrossOrigin
    public JsonResult<Travel_attractions_line> audit(Travel_attractions_line travel_attractions_line)  {
        travelAttractionsLineService.audit(travel_attractions_line);
        return JsonResult.success(travel_attractions_line);
    }

    @Operation(
            summary = "逻辑删除景点路线"
    )
    @PostMapping(MODEL + "/deleteById.json")
    @CrossOrigin
    public JsonResult<Travel_attractions_line> deleteById(Long attractionId) {
        travelAttractionsLineService.delete( attractionId,0);
        return JsonResult.success();
    }
    @Operation(
            summary = "物理删除景点路线"
    )
    @PostMapping(MODEL + "/delete.json")
    @CrossOrigin
    public JsonResult<Travel_attractions_line> delete(Long attractionId) {
        travelAttractionsLineService.delete(attractionId,1);
        return JsonResult.success();
    }

    @Operation(
            summary = "根据导游ID查询所有景点路线"
    )
    @PostMapping(MODEL + "/queryByUserId.json")
    @CrossOrigin
    public JsonResult<List> queryByUserId(Long userId) {
        List<Travel_attractions_line>  travel_attractions_line_vos  = travelAttractionsLineService.queryByUserId(userId);
        return JsonResult.success(travel_attractions_line_vos);
    }
    @Operation(
            summary = "根据状态查询景点路线"
    )
    @PostMapping(MODEL + "/queryByState.json")
    @CrossOrigin
    public JsonResult<List> queryByState(@RequestParam(required = false) Long userId, Integer state) {
        List<Travel_attractions_line>  travel_attractions_line_vos  = travelAttractionsLineService.queryByState(userId,state);
        return JsonResult.success(travel_attractions_line_vos);
    }

    @Operation(
            summary = "根据路线ID查询景点路线"
    )
    @PostMapping(MODEL + "/queryById.json")
    @CrossOrigin
    public JsonResult<Travel_attractions_line> queryById(Long attractionId) {
        Travel_attractions_line travel_attractions_line  = travelAttractionsLineService.queryById(attractionId);
        return JsonResult.success(travel_attractions_line);
    }



    @Operation(
            summary = "查询未审核的景点路线"
    )
    @PostMapping(MODEL + "/queryNoAudit.json")
    @CrossOrigin
    public JsonResult<List> queryNoAudit() {
        List<Travel_attractions_line>  travel_attractions_line  = travelAttractionsLineService.queryNoAudit();
        return JsonResult.success(travel_attractions_line);
    }



}
